<?php
/*
 * Copyright (c) 2011 Todd Brady
 *
 * PS3Theatre is freely distributable under the terms of the MIT license.
 * For details, see the MIT-Liscence web site: http://www.opensource.org/licenses/mit-license.php 
 */
 	include_once("includes/db_connect.php");
	
	$weatherQuery = "SELECT zip_code,night_mode,night_start,night_end from tbl_weather";
	$settingsQuery = "SELECT s.version, s.move_the FROM tbl_settings s";
	$cacheDirQuery = "SELECT d.computer_path, d.http_path FROM tbl_directories d, tbl_types t WHERE d.type_id=t.id AND t.type='Main'";
	$wolQuery = "SELECT w.id, w.mac_address, w.secure_on, w.broadcast_address, w.cidr, w.port FROM tbl_wakeonlan w";
	$weather=mysql_query($weatherQuery) or die(mysql_error());
	$settings=mysql_query($settingsQuery) or die(mysql_error());
	$dirs=mysql_query($cacheDirQuery) or die(mysql_error());
	$wols=mysql_query($wolQuery) or die(mysql_error());
	$weatherRow = mysql_fetch_array($weather);
	$settingsRow = mysql_fetch_array($settings);
	$wolRow = mysql_fetch_array($wols);
	$moveThe = $settingsRow['move_the'];
	if(mysql_num_rows($dirs) > 0){
		$cacheDirRow = mysql_fetch_array($dirs);
		$cacheHttp = $cacheDirRow['http_path'];
		$cacheComp = $cacheDirRow['computer_path'];
	}
	$zipCode = $weatherRow['zip_code'];
	$nightMode = $weatherRow['night_mode'];
	$nightStart = $weatherRow['night_start'];
	$nightEnd = $weatherRow['night_end'];
	
	$message = $_GET['message'];
?>
	
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<LINK href="../css/main.css" rel="stylesheet" type="text/css">
</head>

<body>
<?php echo $message; ?>
<h4>Database</h4>
<p>
  <label>Recreate Database if you need to start from scratch
  <input type="button" name="recreateBtn" value="Recreate Database" onclick="if(confirm('This action will delete the current database and start from scratch\n\nARE YOU SURE YOU WANT TO PROCEED?')){location='createDatabase.php?action=recreate';}"/>
  </label>
</p>
<p>&nbsp;</p>
<h4>Settings   
  <input type="button" name="mainSettingButton" value="Edit" onclick="location='main-edit.php'"/></h4>
<table width="572" border="0" cellpadding="0" cellspacing="0" id="0">
  <tr>
    <td width="288"><strong>Move The: </strong></td>
    <td width="268"><label>
	<input name="checkbox" type="checkbox" value="checkbox" <?php if($moveThe=='Y'){echo 'checked="checked"';}?> disabled="disabled"/>
    </label></td>
  </tr>
  <tr>
    <td width="288"><strong>Cache http dir: </strong></td>
    <td width="268"><label>
      <?php echo $cacheHttp;?>
    </label></td>
  </tr>
  <tr>
    <td width="288"><strong>Cache Comp dir: </strong></td>
    <td width="268"><label>
      <?php echo $cacheComp;?>
    </label></td>
  </tr>

</table>
<p>&nbsp;</p>
<h4>Weather   <input type="button" name="weatherSettingButton" value="Edit" onclick="location='weather-edit.php'"/></h4>
<table width="572" border="0" cellpadding="0" cellspacing="0" id="0">
  <tr>
    <td width="288"><strong>Zip Code: </strong></td>
    <td width="268"><label>
      <?php echo $zipCode;?>
    </label></td>
  </tr>
  <tr>
    <td><strong>Show Moon at Night: </strong></td>
    <td><label>
      <input name="checkbox" type="checkbox" value="checkbox" <?php if($nightMode=='Y'){echo 'checked="checked"';}?> disabled="disabled"/>
    </label></td>
  </tr>
  <tr>
    <td><strong>Show Moon Start Time(24hr clock): </strong></td>
    <td><label>
      <?php echo $nightStart; ?>
    </label></td>
  </tr>
  <tr>
    <td><strong>Show Moon End Time(24hr clock): </strong></td>
    <td>      <?php echo $nightEnd; ?></td>
  </tr>
</table>
<p>&nbsp;</p>
<h4>Wake On LAN   
  <input type="button" name="mainSettingButton" value="Edit" onclick="location='wol-edit.php'"/></h4>
<table width="572" border="0" cellpadding="0" cellspacing="0" id="0">
  <tr>
    <td width="288"><strong>Mac Address: </strong></td>
    <td width="268"><label><?php echo $wolRow['mac_address'];?>    </label></td>
  </tr>
  <tr>
    <td width="288"><strong>Secure On: </strong></td>
    <td width="268"><label>
      <input name="checkbox2" type="checkbox" value="checkbox" <?php if($wolRow['secure_on']=='Y'){echo 'checked="checked"';}?> disabled="disabled"/>
    </label></td>
  </tr>
  <tr>
    <td width="288"><strong>Broadcast Address : </strong></td>
    <td width="268"><label>
      <?php echo  $wolRow['broadcast_address'];?>
    </label></td>
  </tr>
  <tr>
    <td><strong>CIDR :</strong></td>
    <td><?php echo  $wolRow['cidr'];?></td>
  </tr>
  <tr>
    <td><strong>Port :</strong></td>
    <td><?php echo  $wolRow['port'];?></td>
  </tr>
  </table>
</body>
</html>
